package com.ruoyi.imweb.core;

import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.websocket.config.INettyConfig;
import com.ruoyi.websocket.handler.IMessageProcessor;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 测试用，实际要自己定义
 */
@Component
@Slf4j
public class ImMessageProcessor implements IMessageProcessor {
    @Autowired
    private INettyConfig iNettyConfig;

    @Override
    public void handlerAdded(ChannelHandlerContext ctx) {
        allChannel.put(ctx.channel().id().asLongText(), ctx);
        log.info("新的连接加入");
    }

    @Override
    public void processJson(JSONObject json, ChannelHandlerContext ctx, TextWebSocketFrame frame) {
        log.info("receive_processJson:{}", json);

    }

    @Override
    public void handlerRemoved(ChannelHandlerContext ctx) {
        allChannel.remove(ctx.channel().id().asLongText());
        log.info("连接已关闭");
    }
}
